#include <iostream>
#include <stack>
#include<vector>
using namespace std;
void split(string a, vector<string> &b) {
    a += " ";
    string s;
    for (int i = 0; i < a.length(); i++) {
        if (a[i] == ' ') {
            if (!s.empty()) {
                b.push_back(s);
                s = "";
            }
        } else {
            s += a[i];
        }
    }
}
int main() {
    string inp;
    vector<string> vec;
    stack<string> stk;
    getline(cin, inp);
    split(inp, vec);
    for (auto i = vec.begin(); i != vec.end(); i++) {
        string s = *i;
        if (s == "+" || s == "-" || s == "*" || s == "/") {
            if (stk.empty()) {
                cout << "Error : Input error" << endl;
                return 1;
            }
            int b = stoi(stk.top()); stk.pop();
            int c = stoi(stk.top()); stk.pop();
            int result;
            if (s == "+") {
                result = c + b;
            } else if (s == "-") {
                result = c - b;
            } else if (s == "*") {
                result = c * b;
            } else {
                if (b == 0) {
                    cout << "Error: Division by zero" << endl;
                    return 1;
                }
                result = c / b;
            }
            stk.push(to_string(result));
        } else {
            stk.push(s);
        }
    }
    if (!stk.empty()) {
        cout << stk.top() << endl;
    } else {
        cout << "Error: Empty input or invalid expression" << endl;
        return 1;
    }
    return 0;
}
